#ifndef __ARTIST_PETALFS_H__
#define __ARTIST_PETALFS_H__
/*
                                                 The name of this file system is "Petal" ,
                                                Which girl loves me ? A poor guy,hehehe ^_^
                                              I should try my best to earn lots of money ,
                                             and make my sons or daughters have the confidence
                                                    to love the one they want to love.
*/
#define PETAL_MAGIC               (0x4E454843)
#define PETAL_EXTENDED            (0xFFFF)

#define PETAL_INVALID             (0)  

#define PETAL_CONTINUOUS          (1)

#define PETAL_CONTENT             (2)

#define PETAL_FILE                (3)
#define PETAL_DIRECTORY           (4)

#define PETAL_SINGLEEMPTY         (5)
#define PETAL_CONTINUOUSEMPTY     (6)


typedef struct struct_fsmemorycontrol
        {
         	U4B 	usrnumber;
	        U4B 	attribute;/* bit0:1 valid;bit1:1  fixed.bit2:1 changed*/
            ULLONG  fromcluster;    
			ULLONG  fileid;
			ULLONG  offset;
        }FSMEMORYCONTROL;
typedef struct struct_fsmemorycontrol* PFSMEMORYCONTROL;




typedef struct struct_sector
        {U4B pad[128];}SECTOR;
typedef struct struct_sector* PSECTOR;




typedef struct struct_cluster
        {SECTOR pad[8];}CLUSTER;
typedef struct struct_cluster* PCLUSTER;





typedef struct struct_directoryitem  /*128 Bytes.*/
        {
          U4B    e_type;/*PETAL_INVALID ,PETAL_DIRECTORY,PETAL_FILE*/
          U4B    e_flags;

          ULLONG e_startcluster;
          ULLONG e_attribute;
          ULLONG e_size;/*bytes number, item number.*/
          ULLONG e_nameblock;   
          ULLONG e_id;
          ULLONG e_pad2;/*--------------TODO------------------*/

          U4B    e_usr;
          U4B    e_usrgroup;
          U4B    e_creater;
          U4B    e_owner;

          U4B    e_accesstime;
          U4B    e_createtime;
          U4B    e_mendtime;
          U4B    e_deletetime;

          U4B    e_linknumber;
          U4B    e_privilege;
          CHAR   e_name[32];
        }DIRECTORYITEM;
typedef struct struct_directoryitem* PDIRECTORYITEM;




typedef struct struct_directorylinker /*128bytes*/
        {
          ULLONG l_previous;
          ULLONG l_next;
          ULLONG l_upper;
		  
          U4B    l_upperindex;
		  U4B    l_pad0;
          ULLONG l_pad3;   
          ULLONG l_pad4;
          ULLONG l_pad5;
          ULLONG l_pad6;
		  ULLONG l_pad7;
		  ULLONG l_pad8;
		  ULLONG l_pad9;
		  ULLONG l_pad10;
		  ULLONG l_pad11;
		  ULLONG l_pad12;
		  ULLONG l_pad13;
		  ULLONG l_pad14;
        }DIRECTORYLINKER;







typedef struct struct_petaldirectory
        {
            DIRECTORYITEM   entry[31];
			DIRECTORYLINKER linker;
        }PETALDIRECTORY;
typedef struct struct_petaldirectory* PPETALDIRECTORY;




typedef struct struct_fileitem /* 32 Bytes.*/
        {
            U4B    f_type;/*PETAL_INVALID ,PETAL_EXTENDED,PETAL_CONTINUOUS,PETAL_CONTENT*/
            U4B    f_pad0;
            ULLONG f_startcluster;
            ULLONG f_size;  
            ULLONG f_pad1;
        }FILEITEM;
typedef struct struct_fileitem* PFILEITEM;






typedef struct struct_fileheader/*64bytes*/
        {
            U2B    h_upperindex;
			U2B    h_index;
			U2B    h_firstindex;
			U2B    h_secondindex;
			ULLONG h_upper;
			ULLONG h_firstoffset;
			ULLONG h_secondoffset;
			ULLONG h_level;       /*it must be  continuous .*/
			ULLONG h_pad2;
			ULLONG h_pad3;
			ULLONG h_pad4;
        }FILEHEADER;
typedef struct struct_fileheader* PFILEHEADER;






typedef struct struct_petalfile
        {
            FILEHEADER head;
            FILEITEM section[126];
        }PETALFILE;
typedef struct struct_petalfile* PPETALFILE;




typedef struct struct_super /*4096bytes= 512*8Bytes*/
        {
           SECTOR           s_boot;
           /*--------------128 Bytes---------------*/
            U4B             s_pad0;
            U4B             s_magic;
            U4B             s_flags;/*the last one bit:0 use 32bits,1 use 64bits*/
            U4B             s_clustersize;
            U4B             s_directoryitemsize;
            U4B             s_fileitemsize;
            ULLONG          s_clustersum;
            ULLONG          s_remainnumber;
            ULLONG          s_virgincluster;
            ULLONG          s_freecluster;
			ULLONG          s_distributeid;
            ULLONG          s_pad[8];
           /*---------------384 Bytes--------------*/
            DIRECTORYITEM   s_root;        
            DIRECTORYITEM   s_pad10;   
            DIRECTORYITEM   s_pad11;
            /*-------------6 sectors---------------*/
            SECTOR      s_sectorpad[6];                
        }SUPER;
typedef struct struct_super* PSUPER;





typedef struct struct_empty /*32bytes*/
        {
           U4B       t_type;
		   U4B       t_pad0;
		   ULLONG    t_number;
           ULLONG    t_startcluster;
		   ULLONG    t_pad1;
        }EMPTY;
typedef  struct struct_empty *  PEMPTY;

typedef struct struct_dustbin
        {
            EMPTY resource[128];
        }DUSTBIN;
typedef struct struct_dustbin* PDUSTBIN;

#define IamaInvalidULLONGEntity(u) (u.low==PETAL_INVALID && u.high==PETAL_INVALID)
#define IamaInvalidPointer(p) (p->low==PETAL_INVALID && p->high==PETAL_INVALID)
#define FSControlToAddress(control) ((((PU1B)fscontrol)+sizeof(CLUSTER)*control))
#define IamaZeroULLONGEntity(u)  (u.low==0 && u.high==0)

#endif
